﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Service
{
    internal class SystemMessage : Subject
    {
        public string FailureMessage { get; set; }
        List<Observer> observers;

        public SystemMessage()
        {
            observers = new List<Observer>();
        }
        public void Attach(Observer observer)
        {
            observers.Add(observer);
        }

        public void Detach(Observer observer)
        {
            //int index = observers.IndexOf(observer);
            observers.Remove(observer);
        }

        public void NotifyObservers()
        {
            foreach (var item in observers)
            {
                item.Alert(FailureMessage);
            }
        }

        public void Execute()
        {
            NotifyObservers();
        }
    }
}